function yld =  yldoddf(sd,md,id,fd,rv,price,cpn,per,basis)
%YLDODDF Yield of security with odd first period.
%   YLD = YLDODDF(SD,MD,ID,FD,RV,PRICE,CPN,PER,BASIS,MAXITER)
%   returns the yield of a security with an odd first period and the
%   settlement date in the first period.
%
%   yld = yldoddf(sd,md,id,fd,rv,price,cpn)
%   yld = yldoddf(sd,md,id,fd,rv,price,cpn,per)
%   yld = yldoddf(sd,md,id,fd,rv,price,cpn,per,basis)
%
%   Enter dates as serial date numbers or date strings.
%
%   Inputs:
%       SD      -  Settlement date
%       MD      -  Maturity date
%       ID      -  Issue date
%       FD      -  First coupon date
%       RV      -  Par value
%       PRICE   -  Price
%       CPN     -  Coupon rate
%
%  Optional Inputs:
%       PER     - the number of coupon periods per year
%                  1 - annual
%                  2 - semi-annual (default)
%                  3 - three times per year
%                  4 - quarterly
%                  6 - bi-monthly
%                 12 - monthly
%
%       BASIS   -  the day-count basis:
%                  0 = actual/actual (default)
%                  1 = 30/360 SIA
%                  2 = actual/360
%                  3 = actual/365
%                  4 = 30/360 PSA
%                  5 = 30/360 ISDA
%                  6 = 30E/360
%                  7 = actual/365 Japanese
%                  8 - actual/actual ISMA
%                  9 - actual/360 ISMA
%                 10 - actual/365 ISMA
%                 11 - 30/360 ISMA
%                 12 - actual/365 ISDA
%
%   Using the following data,
%
%        SD = '11/11/1992'
%        MD = '03/01/2005'
%        ID = '10/15/1992'
%        FD = '03/01/1993'
%        RV = 100
%        PRICE = 113.60
%        CPN = 0.0785
%        PER = 2
%        BASIS = 0
% 
%   yld = yldoddf(sd,md,id,fd,rv,price,cpn,per,basis)
%
%   returns yld = 0.0625 or 6.25%.
%
%   See also YLDODDL, YLDBOND, YLDODDFL.
%
%   Reference: Mayle, Standard Securities Calculation Methods, Volumes
%              I-II, 3rd edition.  Formulas 8, 9.

% Copyright 1995-2006 The MathWorks, Inc.
% $Revision: 1.7.2.8 $   $Date: 2007/11/07 18:30:13 $

if nargin < 9
    basis = 0;
end

if nargin < 8
    per = 2;
end

if nargin < 7
    error('finance:yldoddf:tooFewInputs',...
        'Missing one of SD, MD, ID, FD, RV, CPN, and YLD.');
end

if any(any(ischar(sd) | ischar(md) | ischar(id) | ischar(fd)))
    sd = datenum(sd);
    md = datenum(md);
    id = datenum(id);
    fd = datenum(fd);
end

if length(sd) == 1
    sd = sd*ones(size(md));
end

if length(md) == 1
    md = md*ones(size(sd));
end

if length(id) == 1
    id = id*ones(size(sd));
end

if length(fd) == 1
    fd = fd*ones(size(sd));
end

if length(rv) == 1
    rv = rv*ones(size(sd));
end

if length(price) == 1
    price = price*ones(size(sd));
end

if length(cpn) == 1
    cpn = cpn*ones(size(sd));
end

if length(per) == 1
    per = per*ones(size(sd));
end

if length(basis) == 1
    basis = basis*ones(size(sd));
end

if any(~isvalidbasis(basis))
    error('finance:yldoddf:invalidBasis',...
        'Invalid day count basis specified.');
end

if checksiz([size(sd);size(md);size(id);size(fd);size(rv);size(price);...
        size(cpn);size(per);size(basis)],mfilename)
    return
end

yld = zeros(size(sd));
for i = 1:length(sd(:))
    if checkrng(str2mat('sd','md','cpn','per'),[sd(i),md(i),...
            cpn(i),per(i)],[id(i) fd(i) 0 0],[fd(i) inf inf inf],...
            str2mat('id','fd','0','0'),...
            str2mat('fd','inf','inf','inf'),['e';'e';'e';'l'],...
            ['e';'l';'l';'l'],mfilename)
        return
    end
    if checktyp('per',per(i),'int',mfilename);return;end
end % end for loop

yld = bndyield(price,cpn,sd,md,per,basis,[],id,fd,[],[],rv);

% [EOF]
